package com.atguigu.lease.common.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ClassName:MybatisMetaObjectHandler
 * Package: com.atguigu.lease.common.mybatisplus
 * Description:
 *
 * @Author Makabaka
 * @Create 2024/9/20 14:45
 * @Version 1.0
 */
@Component
public class MybatisMetaObjectHandler implements MetaObjectHandler {

//自动插入相关的属性值   实现MetaObjectHandler重写方法即可
//    配合@TableFilled(fill = ****) 使用
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        this.strictInsertFill(metaObject,"createTime",Date.class,date);
        this.strictUpdateFill(metaObject,"updateTime",Date.class,date);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,"updateTime",Date.class,new Date());
    }
}
